#pragma once

#include "types.h"
#include <windows.h>

class Timer
{
public:
	Timer();
	void Start();

	UInt32 TimeElapsedSec() const;
	UInt32 TimeElapsedMilliSec() const;
	UInt64 TimeElapsedMicroSec() const;

private:
	Int64 m_start;
	Int64 m_freq;
};



inline Timer::Timer()
{
	Start();
}

inline void Timer::Start()
{
	QueryPerformanceFrequency((LARGE_INTEGER*)&m_freq);
	QueryPerformanceCounter((LARGE_INTEGER*)&m_start);
}

inline UInt32 Timer::TimeElapsedSec() const
{
	Int64 end,diff;
	QueryPerformanceCounter((LARGE_INTEGER*)&end);
	diff = (end - m_start) / m_freq;
	return static_cast<UInt32>(diff & 0xffffffff);
}

inline UInt32 Timer::TimeElapsedMilliSec() const
{
	Int64 end,diff;
	QueryPerformanceCounter((LARGE_INTEGER*)&end);
	diff = ((end - m_start) * 1000) / m_freq;
	return static_cast<UInt32>(diff & 0xffffffff);
}

inline UInt64 Timer::TimeElapsedMicroSec() const
{
	Int64 end,diff;
	QueryPerformanceCounter((LARGE_INTEGER*)&end);
	diff = ((end - m_start) * 1000000) / m_freq;
	return static_cast<UInt64>(diff);
}
